import { Component, OnInit } from '@angular/core';
import {Router,NavigationExtras} from "@angular/router"; //用这个包来跳转路由

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  constructor(private router:Router) { //实例化路由跳转对象

  }

  ngOnInit(): void {
  }
  gonews(){
    //this.router.navigate(['/news'])
    this.router.navigate(['/newscontent','1'])//传2个参数,会组合起来 //http://localhost:4200/newscontent/1
  }
  goshop(aid:any,id:any){
    let navigationExtras:NavigationExtras={ //构建一个参数清单,用于跳转路由时用
      queryParams:{'aid':aid,"id":id}
    };
    this.router.navigate(['/shoplist'],navigationExtras)
  }
}
